<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<body>
<script type="text/javascript" >
$(function() {
	djt_OSR_editIndex = undefined;
	
	$('#djt_OSR_dg').datagrid({
    	url:'../OvertimeRate/querybypage',
    	columns:[[
    		{field:'',title:'',checkbox:true},
			{field:'overtimeSalaryRateId',title:'编号',width:'50',sortable:true},
			{field:'overtimeSalaryRateName',title:'加班倍率名',width:'150'},
			{field:'rate',title:'加班倍率',width:'96',editor:{type:'numberbox',options:{required:true,precision:2}},sortable:true},
			{field:'everydayWorktime',title:'每日工作时间（小时）',width:'160',editor:{type:'numberbox',options:{required:true}},sortable:true},
		]],
		fit:true,
 	   	fitColumns:false,
 	   	//隔行变色
 	   	striped:true,
  	  	nowrap:true,
		toolbar:'#OSRtb',
		pagination:true,
		pageSize:3,
		pageList:[3],
		border:false,
		sortName:'overtimeSalaryRateId',
		sortOrder:'asc',
		onAfterEdit : function(rowIndex,rowData,changes){
			var updated = $('#djt_OSR_dg').datagrid('getChanges','updated');
			var url = '';
			if(updated.length > 0){
				url = '../OvertimeRate/update';
			}
			var djt_OSR_rowData = JSON.stringify(rowData);
			$.post(url,{djt_OSR_rowData},function(e){
				var info = JSON.parse(e);
				//console.log(info);
				if(info.success){
					$('#djt_OSR_dg').datagrid('acceptChanges');
					$.messager.show({
						title:'成功',
						msg:info.msg,
					});
				}else{
					$('#djt_OSR_dg').datagrid('rejectChanges');
					$.messager.alert('错误',info.msg,'error');
				}
			})
			djt_OSR_editIndex = undefined;
			$('#djt_OSR_dg').datagrid('unselectAll');
		},
		onDblClickRow : function(rowIndex,rowData){
			if(djt_OSR_editIndex != undefined){
				$('#djt_OSR_dg').datagrid('endEdit',djt_OSR_editIndex);
				djt_OSR_editIndex = undefined;
			}
			if(djt_OSR_editIndex == undefined){
				$('#djt_OSR_dg').datagrid('beginEdit',rowIndex);
				djt_OSR_editIndex = rowIndex;
			}
		}
	});
});

//保存
function saveOSR(){
	$('#djt_OSR_dg').datagrid('endEdit',djt_OSR_editIndex);
}

//编辑
function editOSR(){
	var rows = $('#djt_OSR_dg').datagrid('getSelections');
	if(rows.length == 1){
		if(djt_OSR_editIndex != undefined){
			$('#djt_OSR_dg').datagrid('endEdit',djt_OSR_editIndex);
		}
		if(djt_OSR_editIndex == undefined){
			var index = $('#djt_OSR_dg').datagrid('getRowIndex',rows[0]);
			$('#djt_OSR_dg').datagrid('beginEdit',index);
			djt_OSR_editIndex = index;
			$('#djt_OSR_dg').datagrid('unselectAll');
		}
	}else{
		$.messager.show({
			title:'提示',
			msg:'一次只能编辑一行！',
		});
	}
}

//撤销编辑
function rejectOSR(){
	djt_OSR_editIndex = undefined;
	$('#djt_OSR_dg').datagrid('rejectChanges');
	$('#djt_OSR_dg').datagrid('unselectAll');
}
</script>

	<div class="easyui-layout" fit="true" border="false">
	<div region="center" border="false">
		<table id="djt_OSR_dg"></table>
	
		<div id="OSRtb">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editOSR()">编辑</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="saveOSR()">保存</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="rejectOSR()">撤销编辑</a>
		</div>
	</div>	
	</div>
</body>